package ca.eloas.gpsclock.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import ca.eloas.gpsclock.R;
import ca.eloas.gpsclock.db.AlarmDatabase;
import ca.eloas.gpsclock.db.TimeAlarmInfo;
import ca.eloas.gpsclock.service.AlarmClockService;

import java.util.Random;

/**
 * User: jpbelang
 * Date: Jul 24, 2010
 * Time: 11:56:08 PM
 */
public class MainActivity extends Activity {


    private AlarmDatabase database;

    public void onStart() {

        super.onStart();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        TextView v = (TextView) findViewById(R.id.Clock);
        database = new AlarmDatabase(this);
        database.deleteAllAlarms();

        TimeAlarmInfo timeAlarmInfo = new TimeAlarmInfo(Math.abs(new Random().nextInt() % 24), Math.abs(new Random().nextInt() % 60));
        timeAlarmInfo.setActive(true);
        database.saveAlarm(timeAlarmInfo);

        timeAlarmInfo = new TimeAlarmInfo(Math.abs(new Random().nextInt() % 24), Math.abs(new Random().nextInt() % 60));
        timeAlarmInfo.setActive(true);
        database.saveAlarm(timeAlarmInfo);

        startService(new Intent(this, AlarmClockService.class));
    }


    @Override
    protected void onDestroy() {

        stopService(new Intent(this, AlarmClockService.class));
        super.onDestroy();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {

        super.onStop();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {

            case R.id.new_time_alarm:
                return false;

            case R.id.new_geo_alarm:
                break;

            default:
                return false;
        }

        return true;
    }

    public boolean onCreateOptionsMenu(Menu menu) {

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.clock_menu, menu);

        MenuItem mi = menu.findItem(R.id.new_time_alarm);
        mi.setIntent(new Intent(this, AlarmActivity.class));
        
        return true;
    }
}
